﻿/*
 * 最常用的设计模式
 * 设计模式 - 外观模式
 * 目的: 隐藏复杂的实现, 客户端很简单的去掉用,隐藏掉内部的实现
 */

/*
 * API GateWay 就是一个外观模式
 */




var facade = new Facade();
var res = facade.GetUserAuthors(1);


interface IUserRepository
{
    object GetById(in int id);
}

interface IRoleRepository
{
    IEnumerable<string> GetRoles(in int id);
}

interface IAuthorRepository
{
    IEnumerable<string> GetAuthors(IEnumerable<string> roles);
}


public class Facade
{
    private readonly IUserRepository _userRepository;
    private readonly IRoleRepository _roleRepository;
    private readonly IAuthorRepository _authorRepository;
    public Facade()
    {

    }

    public IEnumerable<string> GetUserAuthors(in int userId)
    {
        var user = _userRepository.GetById(userId);

        var roles = _roleRepository.GetRoles(userId);

        var authors = _authorRepository.GetAuthors(roles);

        return authors;
    }
}